package com.lesserpand.springcloudalibabacore.config.rabbitmq.callback;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;

/**
 * 异步confirm，实现ConfirmCallback接口用于消息发送到RabbitMQ交换器后接收ack回调。
 * 消息发送到交换机确认机制。如果不设置这个，可以用备份交换器保证消息可靠发送
 *
 * @author pand
 */
public class MsgSendConfirmCallBack implements RabbitTemplate.ConfirmCallback {

    private static final Logger LOGGER = LoggerFactory.getLogger(MsgSendConfirmCallBack.class);

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
            LOGGER.info("消息发送成功, :MsgSendConfirmCallBack  , 回调id:" + correlationData);
        } else {
            LOGGER.error("消息发送失败:" + cause + "\n重新发送");
        }
    }
}
